package company.tx;

import java.util.Scanner;

public class Tx4 {

    static long min = Integer.MAX_VALUE;

    // 没有考虑到横竖交替印刷的情况
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
        }
        helper(array, 0, 0, 0);
        System.out.println(Math.min(min, n));
    }

    private static void helper(long[] array, long count, int index, long height) {
        if (index == array.length) {
            min = Math.min(min, count);
        } else {
            // 横着刷
            long num = array[index];
            if (num < height)
                //更新高度
                helper(array, count, index + 1, num);
            else
                //新增高度
                helper(array, count + (num - height), index + 1, num);
            // 竖着刷
            if (num > height)
                helper(array, count + 1, index + 1, height);
        }
    }
}
